import _ from './common';
import md5 from './md5';

/**
 * 将公共参数生成签名
 * 
 * @param data
 * @returns {Promise}
 */
function getPublicParams(){
    const params = {};
    params.appId = _.host.appId;
    params.key = _.host.key;

    // 生成签名
    return buildParams(params);
}

/**
 * 生成签名
 * 
 * @param params
 * @returns {*}
 */
function buildParams(params){
    let keyArr = [];
    for (let key in params) {
        keyArr.push(key);
    }
    keyArr = keyArr.sort();
    let keys = keyArr.map((v) => params[v] ? v + '=' +params[v] : '').join('&');
    
    return md5(keys);
}

export default getPublicParams
